package main

import "fmt"

func main() {
	s := []string{"1", "1", "2", "2", "3", "4", "4", "4", "4", "5"}
	fmt.Println(s)
	fmt.Println(removeDupBeside(s))
	//fmt.Println(removeDupBesideShared(s))

	s1 := []string{"a", "b", "b", "b", "c", "b"}
	s1 = removeDupBeside(s1)
	//s1 = removeDupBesideShared(s1)
	fmt.Println(s1)
}

// 自己实现
func removeDupBeside(s []string) []string {
	index := 1
	for i := 1; i < len(s); i++ {
		if i != index {
			if s[index-1] != s[i] {
				s[index] = s[i]
			}
		}
		if s[index-1] != s[i] {
			index++
		}
	}
	return s[:index]
}

// 网上别人分享的
func removeDupBesideShared(strs []string) []string {
	index := 0
	for _, s := range strs {
		if s == strs[index] {
			continue
		}
		index++
		strs[index] = s
	}
	return strs[:index+1]
}
